<?php
/**
 * 用于判断是否为今天还是昨天
 * @param string $publishDate
 */
function smarty_modifier_wtime($publishDate) {
	$dur = time () - $publishDate;
	$current = date ( "Y", time () );
	$publish = date ( "Y", $publishDate );
	
	switch ($dur) {
		case $dur < 60 :
			return "刚刚";
			break;
		case $dur < 3600 && $dur > 60 :
			return "" . floor ( $dur / 60 ) . '分钟前';
			break;
		
		case $dur < 86400 && $dur > 3600 :
			return "" . floor ( $dur / 3600 ) . "小时前";
			break;
		case $dur > 86400 && $dur < 86400 * 2 :
			return "1天前";
		case $dur > 86400 * 2 && $dur < 86400 * 3 :
			return "2天前";
			break;
		case $dur > 86400 * 3 && $dur < 86400 * 7 :
			return "3天前";
			break;
		case $dur > 86400 * 7 && $dur < 86400 * 14 :
			return "1周前";
			break;
		case $dur < 259200 :
			return date ( "m/d H:i", $publishDate );
			
			break;
	}
	
	if ($current == $publish) {
		return date ( "m/d", $publishDate );
	} else {
		return date ( "Y/m/d", $publishDate );
	}
	
	return "无法获取时间";

}

